home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3 / perl5 / DynaLoader.z / DynaLoader
Encoding:
Text File  |  1998-10-30  |  17.7 KB  |  529 lines

  1.  
  2.  
  3.  
  4. DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr((((3333))))                                                    DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr((((3333))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      DynaLoader - Dynamically load C libraries into Perl code
  10.  
  11.      _d_l__e_r_r_o_r(), _d_l__f_i_n_d_f_i_l_e(), _d_l__e_x_p_a_n_d_s_p_e_c(), _d_l__l_o_a_d__f_i_l_e(),
  12.      _d_l__f_i_n_d__s_y_m_b_o_l(), _d_l__f_i_n_d__s_y_m_b_o_l__a_n_y_w_h_e_r_e(), _d_l__u_n_d_e_f__s_y_m_b_o_l_s(),
  13.      _d_l__i_n_s_t_a_l_l__x_s_u_b(), _d_l__l_o_a_d__f_l_a_g_s(), _b_o_o_t_s_t_r_a_p() - routines used by
  14.      DynaLoader modules
  15.  
  16. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  17.          package YourPackage;
  18.          require DynaLoader;
  19.          @ISA = qw(... DynaLoader ...);
  20.          bootstrap YourPackage;
  21.  
  22.          # optional method for 'global' loading
  23.          sub dl_load_flags { 0x01 }
  24.  
  25.  
  26. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  27.      This document defines a standard generic interface to the dynamic linking
  28.      mechanisms available on many platforms.  Its primary purpose is to
  29.      implement automatic dynamic loading of Perl modules.
  30.  
  31.      This document serves as both a specification for anyone wishing to
  32.      implement the DynaLoader for a new platform and as a guide for anyone
  33.      wishing to use the DynaLoader directly in an application.
  34.  
  35.      The DynaLoader is designed to be a very simple high-level interface that
  36.      is sufficiently general to cover the requirements of SunOS, HP-UX, NeXT,
  37.      Linux, VMS and other platforms.
  38.  
  39.      It is also hoped that the interface will cover the needs of OS/2, NT etc
  40.      and also allow pseudo-dynamic linking (using ld -A at runtime).
  41.  
  42.      It must be stressed that the DynaLoader, by itself, is practically
  43.      useless for accessing non-Perl libraries because it provides almost no
  44.      Perl-to-C 'glue'.  There is, for example, no mechanism for calling a C
  45.      library function or supplying arguments.  A ExtUtils::DynaLib module is
  46.      available from CPAN sites which performs that function for some common
  47.      system types.
  48.  
  49.      DynaLoader Interface Summary
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr((((3333))))                                                    DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr((((3333))))
  71.  
  72.  
  73.  
  74.        @dl_library_path
  75.        @dl_resolve_using
  76.        @dl_require_symbols
  77.        $dl_debug
  78.        @dl_librefs
  79.        @dl_modules
  80.                                                        Implemented in:
  81.        bootstrap($modulename)                               Perl
  82.        @filepaths = dl_findfile(@names)                     Perl
  83.        $flags = $modulename->dl_load_flags                  Perl
  84.        $symref  = dl_find_symbol_anywhere($symbol)          Perl
  85.  
  86.        $libref  = dl_load_file($filename, $flags)           C
  87.        $symref  = dl_find_symbol($libref, $symbol)          C
  88.        @symbols = dl_undef_symbols()                        C
  89.        dl_install_xsub($name, $symref [, $filename])        C
  90.        $message = dl_error                                  C
  91.  
  92.  
  93.      @dl_library_path
  94.          The standard/default list of directories in which _d_l__f_i_n_d_f_i_l_e() will
  95.          search for libraries etc.  Directories are searched in order:
  96.          $dl_library_path[0], [1], ... etc
  97.  
  98.          @dl_library_path is initialised to hold the list of 'normal'
  99.          directories (/_u_s_r/_l_i_b, etc) determined by CCCCoooonnnnffffiiiigggguuuurrrreeee
  100.          ($Config{'libpth'}).  This should ensure portability across a wide
  101.          range of platforms.
  102.  
  103.          @dl_library_path should also be initialised with any other
  104.          directories that can be determined from the environment at runtime
  105.          (such as LD_LIBRARY_PATH for SunOS, LD_LIBRARYN32_PATH for IRIX -n32
  106.          binaries).
  107.  
  108.          After initialisation @dl_library_path can be manipulated by an
  109.          application using push and unshift before calling _d_l__f_i_n_d_f_i_l_e().
  110.          Unshift can be used to add directories to the front of the search
  111.          order either to save search time or to override libraries with the
  112.          same name in the 'normal' directories.
  113.  
  114.          The load function that _d_l__l_o_a_d__f_i_l_e() calls may require an absolute
  115.          pathname.  The _d_l__f_i_n_d_f_i_l_e() function and @dl_library_path can be
  116.          used to search for and return the absolute pathname for the
  117.          library/object that you wish to load.
  118.  
  119.      @dl_resolve_using
  120.          A list of additional libraries or other shared objects which can be
  121.          used to resolve any undefined symbols that might be generated by a
  122.          later call to _l_o_a_d__f_i_l_e().
  123.  
  124.          This is only required on some platforms which do not handle dependent
  125.          libraries automatically.  For example the Socket Perl extension
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr((((3333))))                                                    DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr((((3333))))
  137.  
  138.  
  139.  
  140.          library (_a_u_t_o/_S_o_c_k_e_t/_S_o_c_k_e_t._s_o) contains references to many socket
  141.          functions which need to be resolved when it's loaded.  Most platforms
  142.          will automatically know where to find the 'dependent' library (e.g.,
  143.          /_u_s_r/_l_i_b/_l_i_b_s_o_c_k_e_t._s_o).  A few platforms need to be told the location
  144.          of the dependent library explicitly.  Use @dl_resolve_using for this.
  145.  
  146.          Example usage:
  147.  
  148.              @dl_resolve_using = dl_findfile('-lsocket');
  149.  
  150.  
  151.      @dl_require_symbols
  152.          A list of one or more symbol names that are in the library/object
  153.          file to be dynamically loaded.  This is only required on some
  154.          platforms.
  155.  
  156.      @dl_librefs
  157.          An array of the handles returned by successful calls to
  158.          _d_l__l_o_a_d__f_i_l_e(), made by bootstrap, in the order in which they were
  159.          loaded.  Can be used with _d_l__f_i_n_d__s_y_m_b_o_l() to look for a symbol in
  160.          any of the loaded files.
  161.  
  162.      @dl_modules
  163.          An array of module (package) names that have been bootstrap'ed.
  164.  
  165.      dl_error()
  166.          Syntax:
  167.  
  168.              $message = dl_error();
  169.  
  170.          Error message text from the last failed DynaLoader function.  Note
  171.          that, similar to errno in unix, a successful function call does not
  172.          reset this message.
  173.  
  174.          Implementations should detect the error as soon as it occurs in any
  175.          of the other functions and save the corresponding message for later
  176.          retrieval.  This will avoid problems on some platforms (such as
  177.          SunOS) where the error message is very temporary (e.g., _d_l_e_r_r_o_r()).
  178.  
  179.      $dl_debug
  180.          Internal debugging messages are enabled when $dl_debug is set true.
  181.          Currently setting $dl_debug only affects the Perl side of the
  182.          DynaLoader.  These messages should help an application developer to
  183.          resolve any DynaLoader usage problems.
  184.  
  185.          $dl_debug is set to $ENV{'PERL_DL_DEBUG'} if defined.
  186.  
  187.          For the DynaLoader developer/porter there is a similar debugging
  188.          variable added to the C code (see dlutils.c) and enabled if Perl was
  189.          built with the ----DDDDDDDDEEEEBBBBUUUUGGGGGGGGIIIINNNNGGGG flag.  This can also be set via the
  190.          PERL_DL_DEBUG environment variable.  Set to 1 for minimal information
  191.          or higher for more.
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr((((3333))))                                                    DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr((((3333))))
  203.  
  204.  
  205.  
  206.      dl_findfile()
  207.          Syntax:
  208.  
  209.              @filepaths = dl_findfile(@names)
  210.  
  211.          Determine the full paths (including file suffix) of one or more
  212.          loadable files given their generic names and optionally one or more
  213.          directories.  Searches directories in @dl_library_path by default and
  214.          returns an empty list if no files were found.
  215.  
  216.          Names can be specified in a variety of platform independent forms.
  217.          Any names in the form ----llllnnnnaaaammmmeeee are converted into _l_i_b_n_a_m_e.*, where .*
  218.          is an appropriate suffix for the platform.
  219.  
  220.          If a name does not already have a suitable prefix and/or suffix then
  221.          the corresponding file will be searched for by trying combinations of
  222.          prefix and suffix appropriate to the platform: "$name.o",
  223.          "lib$name.*"  and "$name".
  224.  
  225.          If any directories are included in @names they are searched before
  226.          @dl_library_path.  Directories may be specified as ----LLLLddddiiiirrrr.  Any other
  227.          names are treated as filenames to be searched for.
  228.  
  229.          Using arguments of the form -Ldir and -lname is recommended.
  230.  
  231.          Example:
  232.  
  233.              @dl_resolve_using = dl_findfile(qw(-L/usr/5lib -lposix));
  234.  
  235.  
  236.      dl_expandspec()
  237.          Syntax:
  238.  
  239.              $filepath = dl_expandspec($spec)
  240.  
  241.          Some unusual systems, such as VMS, require special filename handling
  242.          in order to deal with symbolic names for files (i.e., VMS's Logical
  243.          Names).
  244.  
  245.          To support these systems a _d_l__e_x_p_a_n_d_s_p_e_c() function can be
  246.          implemented either in the _d_l_*._x_s file or code can be added to the
  247.          autoloadable _d_l__e_x_p_a_n_d_s_p_e_c() function in _D_y_n_a_L_o_a_d_e_r._p_m.  See
  248.          _D_y_n_a_L_o_a_d_e_r._p_m for more information.
  249.  
  250.      dl_load_file()
  251.          Syntax:
  252.  
  253.              $libref = dl_load_file($filename, $flags)
  254.  
  255.          Dynamically load $filename, which must be the path to a shared object
  256.          or library.  An opaque 'library reference' is returned as a handle
  257.          for the loaded object.  Returns undef on error.
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr((((3333))))                                                    DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr((((3333))))
  269.  
  270.  
  271.  
  272.          The $flags argument to alters dl_load_file behaviour. Assigned bits:
  273.  
  274.           0x01  make symbols available for linking later dl_load_file's.
  275.                 (only known to work on Solaris 2 using dlopen(RTLD_GLOBAL))
  276.                 (ignored under VMS; this is a normal part of image linking)
  277.  
  278.          (On systems that provide a handle for the loaded object such as SunOS
  279.          and HPUX, $libref will be that handle.  On other systems $libref will
  280.          typically be $filename or a pointer to a buffer containing $filename.
  281.          The application should not examine or alter $libref in any way.)
  282.  
  283.          This is the function that does the real work.  It should use the
  284.          current values of @dl_require_symbols and @dl_resolve_using if
  285.          required.
  286.  
  287.              SunOS: dlopen($filename)
  288.              HP-UX: shl_load($filename)
  289.              Linux: dld_create_reference(@dl_require_symbols); dld_link($filename)
  290.              NeXT:  rld_load($filename, @dl_resolve_using)
  291.              VMS:   lib$find_image_symbol($filename,$dl_require_symbols[0])
  292.  
  293.          (The _d_l_o_p_e_n() function is also used by Solaris and some versions of
  294.          Linux, and is a common choice when providing a "wrapper" on other
  295.          mechanisms as is done in the OS/2 port.)
  296.  
  297.      dl_loadflags()
  298.          Syntax:
  299.  
  300.              $flags = dl_loadflags $modulename;
  301.  
  302.          Designed to be a method call, and to be overridden by a derived class
  303.          (i.e. a class which has DynaLoader in its @ISA).  The definition in
  304.          DynaLoader itself returns 0, which produces standard behavior from
  305.          _d_l__l_o_a_d__f_i_l_e().
  306.  
  307.      dl_find_symbol()
  308.          Syntax:
  309.  
  310.              $symref = dl_find_symbol($libref, $symbol)
  311.  
  312.          Return the address of the symbol $symbol or undef if not found.  If
  313.          the target system has separate functions to search for symbols of
  314.          different types then _d_l__f_i_n_d__s_y_m_b_o_l() should search for function
  315.          symbols first and then other types.
  316.  
  317.          The exact manner in which the address is returned in $symref is not
  318.          currently defined.  The only initial requirement is that $symref can
  319.          be passed to, and understood by, _d_l__i_n_s_t_a_l_l__x_s_u_b().
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.                                                                         PPPPaaaaggggeeee 5555
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr((((3333))))                                                    DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr((((3333))))
  335.  
  336.  
  337.  
  338.              SunOS: dlsym($libref, $symbol)
  339.              HP-UX: shl_findsym($libref, $symbol)
  340.              Linux: dld_get_func($symbol) and/or dld_get_symbol($symbol)
  341.              NeXT:  rld_lookup("_$symbol")
  342.              VMS:   lib$find_image_symbol($libref,$symbol)
  343.  
  344.  
  345.      dl_find_symbol_anywhere()
  346.          Syntax:
  347.  
  348.              $symref = dl_find_symbol_anywhere($symbol)
  349.  
  350.          Applies _d_l__f_i_n_d__s_y_m_b_o_l() to the members of @dl_librefs and returns
  351.          the first match found.
  352.  
  353.      dl_undef_symbols()
  354.          Example
  355.  
  356.              @symbols = dl_undef_symbols()
  357.  
  358.          Return a list of symbol names which remain undefined after
  359.          _l_o_a_d__f_i_l_e().  Returns () if not known.  Don't worry if your platform
  360.          does not provide a mechanism for this.  Most do not need it and hence
  361.          do not provide it, they just return an empty list.
  362.  
  363.      dl_install_xsub()
  364.          Syntax:
  365.  
  366.              dl_install_xsub($perl_name, $symref [, $filename])
  367.  
  368.          Create a new Perl external subroutine named $perl_name using $symref
  369.          as a pointer to the function which implements the routine.  This is
  370.          simply a direct call to _n_e_w_X_S_U_B().  Returns a reference to the
  371.          installed function.
  372.  
  373.          The $filename parameter is used by Perl to identify the source file
  374.          for the function if required by _d_i_e(), _c_a_l_l_e_r() or the debugger.  If
  375.          $filename is not defined then "DynaLoader" will be used.
  376.  
  377.      bootstrap()
  378.          Syntax:
  379.  
  380.          _b_o_o_t_s_t_r_a_p($module)
  381.  
  382.          This is the normal entry point for automatic dynamic loading in Perl.
  383.  
  384.          It performs the following actions:
  385.  
  386.      +o           locates an auto/$module directory by searching @INC
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.                                                                         PPPPaaaaggggeeee 6666
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400. DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr((((3333))))                                                    DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr((((3333))))
  401.  
  402.  
  403.  
  404.      +o           uses _d_l__f_i_n_d_f_i_l_e() to determine the filename to load
  405.  
  406.      +o           sets @dl_require_symbols to ("boot_$module")
  407.  
  408.      +o           executes an _a_u_t_o/$_m_o_d_u_l_e/$_m_o_d_u_l_e._b_s file if it exists
  409.                  (typically used to add to @dl_resolve_using any files which
  410.                  are required to load the module on the current platform)
  411.  
  412.      +o           calls _d_l__l_o_a_d__f_l_a_g_s() to determine how to load the file.
  413.  
  414.      +o           calls _d_l__l_o_a_d__f_i_l_e() to load the file
  415.  
  416.      +o           calls _d_l__u_n_d_e_f__s_y_m_b_o_l_s() and warns if any symbols are
  417.                  undefined
  418.  
  419.      +o           calls _d_l__f_i_n_d__s_y_m_b_o_l() for "boot_$module"
  420.  
  421.      +o           calls _d_l__i_n_s_t_a_l_l__x_s_u_b() to install it as
  422.                  "${module}::bootstrap"
  423.  
  424.      +o           calls &{"${module}::bootstrap"} to bootstrap the module
  425.                  (actually it uses the function reference returned by
  426.                  dl_install_xsub for speed)
  427.  
  428. AAAAUUUUTTTTHHHHOOOORRRR
  429.      Tim Bunce, 11 August 1994.
  430.  
  431.      This interface is based on the work and comments of (in no particular
  432.      order): Larry Wall, Robert Sanders, Dean Roehrich, Jeff Okamoto, Anno
  433.      Siegel, Thomas Neumann, Paul Marquess, Charles Bailey, myself and others.
  434.  
  435.      Larry Wall designed the elegant inherited bootstrap mechanism and
  436.      implemented the first Perl 5 dynamic loader using it.
  437.  
  438.      Solaris global loading added by Nick Ing-Simmons with design/coding
  439.      assistance from Tim Bunce, January 1996.
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.                                                                         PPPPaaaaggggeeee 7777
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466. DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr((((3333))))                                                    DDDDyyyynnnnaaaaLLLLooooaaaaddddeeeerrrr((((3333))))
  467.  
  468.  
  469.  
  470.  
  471.  
  472.  
  473.  
  474.  
  475.  
  476.  
  477.  
  478.  
  479.  
  480.  
  481.  
  482.  
  483.  
  484.  
  485.  
  486.  
  487.  
  488.  
  489.  
  490.  
  491.  
  492.  
  493.  
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.                                                                         PPPPaaaaggggeeee 8888
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.